﻿using System;
using System.Runtime.Serialization;
using System.Windows;

using Game.ExtensibleObjects;

namespace Game.Map.Internal
{
    [DataContract(Namespace="game")]
    class MapFieldView : IMapFieldView
    {
        public event EventHandler Changed;
        
        readonly MapField _MapField;
        bool _IsVisibe;
        
        public MapFieldView()
        {
        }
        
        public MapFieldView(MapField mapField)
        {
            _MapField = mapField;
            
            _MapField.Changed += delegate(object sender, EventArgs e) 
            {
                if (Changed != null)
                {
                    Changed(sender, e);
                }
            };
            
        }

        public RuntimeExtensionCollection Extensions
        {
            get { return _MapField.Extensions; }
        }

        public bool IsVisible 
        {
            get { return _IsVisibe; }
            set 
            { 
                if (_IsVisibe != value)
                {
                    _IsVisibe=value; 
                    FireChanged(); 
                }
            }
        }
        
        public Point Point 
        {
            get { return _MapField.Point; }
        }
        
        //public IMapItem MapObject 
        //{
        //    get { return _MapField.MapObject; }
        //    set { _MapField.MapObject=value; }
        //}
        
        public bool IsDirty 
        {
            get { return _MapField.IsDirty; }
            set { _MapField.IsDirty=value; }
        }

        void FireChanged()
        {
            if (Changed != null)
            {
                Changed(this, new EventArgs());
            }
        }
        
        public override string ToString()
        {
            return _MapField.ToString();
        }
        
    }
}
